****************************************************************************************************************
**																											  **
** This do file is part of the replication material for the following article: 								  **
**  "Is There an Ideological Asymmetry in the Incumbency Effect? Evidence from U.S. Congressional Elections." **
** 		Authors: Morisi, Davide, Jost, John, Panagopoulos, Costas, and Jussi Valtonen		    			  **
** 		Journal: Social Psychological and Personality Science																			  **
**																											  **
** This file replicates the following step of the analysis: 												  **
**																											  **
**		TABLES AND FIGURES INCLUDED IN APPENDIX	B 														  	  **
**																											  **
****************************************************************************************************************

*Set working directory
cd "C:\Users\Davide Morisi\Dropbox\datasets"

*Open merged dataset
use "CCES\CCES_merged_dataset9.dta", clear

set matsize 800

*Demographics
global demo3 "i.gender birthyr ib2.educ i.racer i.religpewr ib2.economy3"

*Additional controls for House elections
global control_house "i.held_offices2 i.freshman i.redist dexp10 rexp10"
fre held_offices2 freshman redist
fre held_offices2 freshman redist if filter_hou_new==1

*Filter out open seats/seats without 2 major parties in House & Senate
fre filter_hou_new
fre filter_sen1

*Do not use old var for house incumbent & state
rename inc_rep_hou OLD_inc_rep_hou
rename inc_all_hou OLD_inc_all_hou
rename inc_all_hou_filter OLD_inc_all_hou_f
rename own_incLCMpre_hou OLD_own_incLCMpre_hou
rename own_incDRIprof_hou OLD_own_incDRIprof_hou
rename state OLD_state
*New var
rename inc_rep_hou2 inc_rep_hou
rename inc_all_hou2 inc_all_hou
rename own_incLCMpre_hou2 own_incLCMpre_hou
rename own_incDRIprof_hou2 own_incDRIprof_hou
fre inc_all_hou // already filtered
fre inc_rep_hou if filter_hou_new==1

*Districts with alternation
egen mean_rep_inc = mean(inc_rep_hou) if filter_hou_new==1, by(stcd)
fre mean_rep_inc
*ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc==0 // districts with only dem inc
*ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc==1 // districts with only rep inc
ta stcd inc_rep_hou if filter_hou_new==1 & mean_rep_inc>0 & mean_rep_inc<1 // districts with both inc
gen filter_dist = 0 if mean_rep_inc!=.
replace filter_dist = 1 if mean_rep_inc>0 & mean_rep_inc<1
fre filter_dist // 37% districts with alternations

********************************
*APPENDIX B. PARTY IDENTIFICATION
********************************

*
*Correlation PID - ideology
*HOUSE
ta pid2prof ideo2pre if filter_hou_new==1 & votedemrep_hou!=., col chi2 V
pwcorr pid2prof ideo2pre if filter_hou_new==1 & votedemrep_hou!=.
*SENATE
ta pid2prof ideo2pre if filter_sen1==1 & votedemrep_sen!=., col chi2 V
pwcorr pid2prof ideo2pre if filter_sen1==1 & votedemrep_sen!=.

ta pid7prof ideo7pre, col chi2 V
pwcorr pid7prof ideo7pre
pwcorr pid6prof ideo6pre
alpha pid7prof ideo7pre


*
*Table B1. Incumbency effects as a function respondent party identification in Congressional elections (2006-2018) - HOUSE
eststo clear
*1
eststo: logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
*2
eststo: logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
*3 only districts with alternation
eststo: logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
esttab using "~TableB1_HOUSE_R&R.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("TableB1. Incumbency effects, logistic regressions, PID - HOUSE") wide compress noeqlines replace


*
*Table B2. Average marginal effects based on Table B1
eststo clear
*model 1
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==0) post
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==1) post
*model 2
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==0) post
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==1) post
*model 3
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==0) post
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_hou==1) post
*table
esttab using "~TableB2_HOUSE_R&R.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Average marginal effects based on Table B1 - HOUSE") compress noeqlines replace
*incumbency effect, model 1
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou i.stcd i.year if filter_hou_new==1 [pweight=weight1]
margins pid2prof, dydx(own_incDRIprof_hou)
margins r.pid2prof, dydx(own_incDRIprof_hou)
*incumbency effect, model 2
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
margins pid2prof, dydx(own_incDRIprof_hou)
margins r.pid2prof, dydx(own_incDRIprof_hou)
*incumbency effect, model 3
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 & filter_dist==1 [pweight=weight1]
margins pid2prof, dydx(own_incDRIprof_hou)
margins r.pid2prof, dydx(own_incDRIprof_hou)


*
*Table B3. Incumbency effects as a function respondent party identification in Congressional elections (2008-2018) - SENATE
eststo clear
eststo: logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
esttab using "~TableA4_SENATE.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("TableB3 PID - SENATE") wide compress noeqlines replace


*
*Table B4. Average marginal effects based on Table B3
eststo clear
*model 1
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_sen==0) post
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_sen==1) post
*model 2
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_sen==0) post
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo: margins pid2prof, at(own_incDRIprof_sen==1) post
*table
esttab using "~TableB4_SENATE.rtf", ///
b(%6.3f) se(%6.3f) starlevels(* .05 ** .01 *** .001)  scalars (r2) title("Average marginal effects based on Table B3 - SENATE") compress noeqlines replace
*incumbency effect, model 1
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen i.staten i.year if filter_sen1==1 [pweight=weight1]
margins pid2prof, dydx(own_incDRIprof_sen)
margins r.pid2prof, dydx(own_incDRIprof_sen)
*incumbency effect, model 2
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
margins pid2prof, dydx(own_incDRIprof_sen)
margins r.pid2prof, dydx(own_incDRIprof_sen)


*************
*Figure B1. Incumbency effects as a function of respondent partisanship in Congressional elections (2006-2018)

fre pid2prof
*house
eststo clear
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Democrats: margins 1.pid2prof, dydx(own_incDRIprof_hou) post
logit own_candDRIprof_hou i.pid2prof##i.own_incDRIprof_hou $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Republicans: margins 2.pid2prof, dydx(own_incDRIprof_hou) post //
coefplot (Democrats, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(Republicans, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
ytitle("Incumbency effect") title("House") legend(off) ///
graphregion(color(white)) name(figureB1aRR, replace)

*senate
eststo clear
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Democrats_sen: margins 1.pid2prof, dydx(own_incDRIprof_sen) post
logit own_candDRIprof_sen i.pid2prof##i.own_incDRIprof_sen $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Republicans_sen: margins 2.pid2prof, dydx(own_incDRIprof_sen) post
coefplot (Democrats_sen, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
 (Republicans_sen, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
ytitle("") title("Senate") legend(off) ///
graphregion(color(white)) name(figureB1b, replace)

*combined
graph combine figureB1aRR figureB1b, graphregion(color(white)) name(figureB1_pidRR)




*************
*Figure B2. Incumbency effects as a function of respondent ideology and partisanship
fre ideo2pre pid2prof
ta ideo2pre pid2prof, col
gen pid_ambiv = .
replace pid_ambiv = 1 if (ideo2pre==1 & pid2prof==1) | (ideo2pre==2 & pid2prof==2)
replace pid_ambiv = 2 if (ideo2pre==1 & pid2prof==2) | (ideo2pre==2 & pid2prof==1)
label de pid_ambiv 1 "consistent PID" 2 "ambivalent PID"
label val pid_ambiv pid_ambiv
fre pid_ambiv // 11% with ambivalent partisanship

*HOUSE
*consistent PID
eststo clear
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou##i.pid_ambiv $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Liberals_cons: margins 1.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==1) post // lib=.059
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou##i.pid_ambiv $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Conservatives_cons: margins 2.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==1) post // con=.080
coefplot (Liberals_cons, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(Conservatives_cons, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
yscale(range(-.04(.02).30)) ylabel(-.04(.02).30) ///
ytitle("Incumbency effect") title("Consistent Partisanship") legend(off) ///
graphregion(color(white)) name(figureB2a, replace)

*ambivalent PID
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou##i.pid_ambiv $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Liberals_amb: margins 1.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==2) post // lib=.23 (.30)
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou##i.pid_ambiv $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
eststo Conservatives_amb: margins 2.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==2) post // con=.203 (.23)
coefplot (Liberals_amb, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(Conservatives_amb, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
yscale(range(-.04(.02).30)) ylabel(-.04(.02).30) ///
ytitle("") title("Ambivalent partisanship") legend(off) ///
graphregion(color(white)) name(figureB2b, replace)

*combined
graph combine figureB2a figureB2b, title("House") graphregion(color(white)) name(house)
*diff. liberals - conservatives
logit own_candLCMpre_hou i.ideo2pre##i.own_incLCMpre_hou##i.pid_ambiv $demo3 i.stcd i.year if filter_hou_new==1 [pweight=weight1]
margins r.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==1) // consistent: diff. = .010, p=0.125
margins r.ideo2pre, dydx(own_incLCMpre_hou) at(pid_ambiv==2) // ambivalent: diff. = -0.025, p=0.49

*SENATE
eststo clear
*consistent PID
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen##i.pid_ambiv $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Liberals_cons: margins 1.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==1) post // lib=.032
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen##i.pid_ambiv $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Conservatives_cons: margins 2.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==1) post // con=.057
coefplot (Liberals_cons, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(Conservatives_cons, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
yscale(range(-.04(.02).30)) ylabel(-.04(.02).30) ///
ytitle("Incumbency effect") title("Consistent partisanship") legend(off) ///
graphregion(color(white)) name(figureB2c, replace)
*ambivalent PID
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen##i.pid_ambiv $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Liberals_amb: margins 1.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==2) post // lib=.056 (-0.03 - ...)
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen##i.pid_ambiv $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
eststo Conservatives_amb: margins 2.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==2) post // con=.17 (.22)
coefplot (Liberals_amb, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge)) ///
(Conservatives_amb, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(D) msize(medium)), ///
vert yline(0) ///
yscale(range(-.04(.02).30)) ylabel(-.04(.02).30) ///
ytitle("") title("Ambivalent partisanship") legend(off) ///
graphregion(color(white)) name(figureB2d, replace)

*combined
graph combine figureB2c figureB2d, title("Senate") name(senate) graphregion(color(white))
*diff. liberals - conservatives
logit own_candLCMpre_sen i.ideo2pre##i.own_incLCMpre_sen##i.pid_ambiv $demo3 i.staten i.year if filter_sen1==1 [pweight=weight1]
margins r.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==1) // consistent: diff. = .024, p=<0.001
margins r.ideo2pre, dydx(own_incLCMpre_sen) at(pid_ambiv==2) // ambivalent: diff. = .115, p=<0.05

*FINAL
*house + senate
graph combine house senate, graphregion(color(white)) name(figureB2)


